//
//  HMSpringFlowersTableViewController.m
//  HowToDo
//
//  Created by qu on 2017/1/5.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMSpringFlowersTableViewController.h"
#import "HMSpringFlowersPlayMP3Controller.h"
#import "HMSpringFlowsLookListenHearView.h"
#import "HMSpringFlowsTVLookCell.h"
#import "HMSpringFlowersViewModel.h"

@interface HMSpringFlowersTableViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *sfDataArr;
@property (nonatomic, strong) UITableView *tableView;

@end
static NSString *cellID = @"cellID";
@implementation HMSpringFlowersTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    
    
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    tableView.delegate = self;
    tableView.dataSource = self;
    self.tableView = tableView;
    UIView *viewForHeader = [[[UINib nibWithNibName:@"HMSpringFlowsLookListenHearView" bundle:nil] instantiateWithOwner:nil options:nil] lastObject];
    
    self.tableView.tableHeaderView = viewForHeader;
      [self.tableView addTableViewRefreshHeaderWhenPullToPerformAction:@selector(loadData)];
    [self.tableView registerNib:[UINib nibWithNibName:@"HMSpringFlowsTVLookCell" bundle:nil] forCellReuseIdentifier:cellID];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 315;
    

    //-------------设置导航栏开始--------------------------------
    self.navigationItem.title = @"春花儿";
    [super setupNavRightItemsByOne];
    //-------------设置导航栏结束--------------------------------
}



#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.sfDataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   HMSpringFlowsTVLookCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    HMSpringFlowersViewModel *model = self.sfDataArr[indexPath.row];
    
    cell.sfViewModel = model;
 
 return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HMSpringFlowersViewModel *model = self.sfDataArr[indexPath.row];
    
    HMSpringFlowersPlayMP3Controller *viewVC = [[HMSpringFlowersPlayMP3Controller alloc]init];
    
    viewVC.urlStrID = model.tid;
    viewVC.like_count = model.like_count;
    
    [self.navigationController pushViewController:viewVC animated:YES];
    
}

- (void)loadData {
    
    [HMSpringFlowersViewModel loadSpringFlowersDataWithType:35 finishedBlock:^(id resultObject) {
        
        self.sfDataArr = resultObject;
        
        [self.tableView reloadData];
        
        [self.tableView endRefresh];
        
    }];
    
}
//下拉刷新
- (void)loadSpringFlowersData {
    
    [HMSpringFlowersViewModel loadSpringFlowersDataWithType:35 finishedBlock:^(id resultObject) {
       
        
        self.sfDataArr = resultObject;
        
        [self.tableView reloadData];
        
        [self.tableView  endRefresh];
        
    }];
}

@end
